//导航栏公共部分生成
let element = {
  navDivElement(i) {
    let li = `<li class="nav-item">
            <div><p><a href="${iframeHref[i]}" target="iframe"><span class="iconfont ${icon[i]}"></span>${navName[i]}</a></p></div>
        </li>`;
    let ul = $(".nav>ul");
    ul.append(li);
  },
};

//文字图标
let icon = ['icon-shangpinguanli', 'icon-daoyan', 'icon-qing', 'icon-tupian', 'icon-noun-rate-button-901822',
  'icon-14','icon-haoyouliebiao', 'icon-shezhi', 'icon-bangzhu', 'icon-yijianfankui', 'icon-guanyuwomen']

//一级菜单名称
let navName = [
  "商品",
  "影视",
  "天气",
  "图片",
  "接口评价",
  "用户聊天",
  "好友列表",
  "账号设置",
  "帮助中心",
  "意见反馈",
  "关于我们",
];
//二级菜单iframe链接
let iframeHref = [
  "/SYH/HTML/index.html",
  "/HL/HTML/Video.html",
  "/SY/HTML/Weather.html",
  "/CSY/HTML/photo.html",
  '/SYH/HTML/Side_menu.html',
  "/LZB/HTML/chat.html",
  '/LZB/HTML/Friend List.html',
  "/LZB/HTML/AccountSettings.html",
  "/LZB/HTML/HelpCenter.html",
  "/LZB/HTML/Feedback.html",
  "/LZB/HTML/AboutUs.html",
];
//生成导航栏
for (let i = 0; i < navName.length; i++) {
  element.navDivElement(i);
}

$(".nav li>div a").click(function (e) {
  const queryString = window.location.search;
  const urlParams = new URLSearchParams(queryString);
  const paramValue = urlParams.get("id");
  if (paramValue == 'NaN') {
    $('.promptBox').text('请先登录!!!').stop().animate({ 'width': '300px', 'height': '40px' }, 500, function () {
      $(this).animate({ width: '0', height: '0' }, 1000);
  });
    e.preventDefault();
  } else {
    //二级菜单点击事件
    $(".nav-item").click(function () {
      //不允许重复点击
      if ($(this).hasClass("active")) {
        return false;
      }
      $(this).siblings().css({
        borderLeft: "2px solid transparent",
        borderTop: "2px solid transparent",
      });
      $(this).css({
        borderLeft: "2px solid #19aa8d",
        borderTop: "2px solid #19aa8d",
      });
    });
  }
});

//获取页面缩放时的高度
getPageHeight();
function getPageHeight() {
  let height = $(window).height() - 135;
  if (height < 480) {
    $('.nav').find('ul').css({
      'height': height + 'px',
      'overflow': 'auto',
      /* 或者使用 scroll */
      'scrollbar- width': 'none',
      /* 适用于 Firefox */
      '-ms - overflow - style': 'none'
      /* 适用于 IE 和 Edge */
    }
    )
  } else {
    $('.nav').find('ul').css({
      'height': 'auto',
      'overflow': 'hidden',
      'scrollbar- width': 'none',
      '-ms - overflow - style': 'none'
    })
  }
}


$(window).resize(function () {
  getPageHeight();
})